/**
 * @description 交易对手基础信息
 * @author chenyan
 */

import { connect } from 'dva';
import React, { PropTypes, PureComponent } from 'react';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Row, Col, Card, Spin, Calendar, Badge, Empty, Tooltip, Button, Tabs, Modal, Select, message, Pagination } from 'antd';
import { PrimaryC, TableC } from '../../../comps';
import ModalInst from '../../counterpartyManagement/personnelManagement/CommonList/Modal.js';

class PersonalBWeditC extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      businessKey: undefined,
      portfolioList: [], //组合下拉
      shortName: [], //短名下拉
      detailData: {}, //详情
      visible: false, //模态框显示
      currentPage: 1,
      numInPage: 1000,
    };
  }

  componentDidMount() {
    this.setState({
      businessKey: this.props.businessKey,
    });

    //交易对手短名下拉列表
    this.props.dispatch({
      type: 'personalBWdetailM/getShortName',
      payload: {},
      callback: (data) => {
        this.setState({
          shortName: data,
        });
      },
    });
  }

  UNSAFE_componentWillReceiveProps(nextProps) {}
  //    //查询黑白名单 交易对手信息
  queryDetail = () => {
    const { numInPage, currentPage } = this.state;
    this.setState({
      columns: undefined,
      dataSource: undefined, //产品信息
      pageInfo: {},
      type: 'black',
    }); //查询之前清除数据
    this.props.dispatch({
      //查询详情数据
      type: 'personalBWdetailM/getBWList',
      payload: {
        id: this.state.businessKey,
        numInPage,
        currentPage,
      },
      callback: (type, data) => {
        if (type == 'success') {
          this.setState({
            detailData: data.dataSource[0],
          });
        } else {
          this.setState({
            detailData: {},
          });
        }
      },
    });
  };

  //获取编辑信息 并请求后端更新保存
  editData = (values) => {
    const { detailData } = this.state;
    this.props.dispatch({
      //查询详情数据
      type: 'personalBWdetailM/updateBWlist',
      payload: {
        ...detailData,
        id: this.state.businessKey,
        pid: values.shortName2,
        type: detailData.type,
        creator: detailData.creator,
        creaTime: detailData.creaTime,
        status: detailData.status,
      },
      callback: (type) => {
        if (type == 'success') {
          this.setState({
            visible: false,
          });
          this.props.onOk();
        }
      },
    });
  };
  render() {
    const { loading } = this.props;
    const { type, portfolioList, shortName } = this.state;
    const modalProps = {
      titleModal: '交易对手信息编辑',
      type: type,
      portfolioList,
      shortName,
    };
    return (
      <div>
        <PrimaryC
          title={this.props.title}
          onClick={() => {
            this.queryDetail();
            this.setState({ visible: true });
          }}
        />
        <ModalInst
          {...modalProps}
          visible={this.state.visible}
          setVisible={(e) =>
            this.setState({
              visible: e,
            })
          }
          detailData={this.state.detailData}
          getTableDataNew={(e) => {
            this.editData(e);
          }}
        />
      </div>
    );
  }
}

export default connect(({ personalBWdetailM, loading }) => ({ personalBWdetailM, loading }))(PersonalBWeditC);
